package com.ocom.accesservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.accesservice.dao.IDaoRegionInfo;
import com.ocom.accesservice.service.RegionInfoService;
import com.ocom.common.entity.access.EntityMjRegionInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.common.utils.StringUtils;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class RegionInfoServiceImpl extends ServiceImpl<IDaoRegionInfo, EntityMjRegionInfo> implements RegionInfoService {


    @Autowired
    private IDaoRegionInfo daoRegionInfo;

    @DataSourceAspect(type= DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.SLAVE)
    @Override
    public String GetRegionName(Long regionId, Long comId) {
        QueryWrapper<EntityMjRegionInfo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotNull(regionId)) {
            wrapper.eq("region_id", regionId);
        }
        wrapper.last("limit 1");
        EntityMjRegionInfo entityMjRegionInfo = daoRegionInfo.selectOne(wrapper);
        if (entityMjRegionInfo == null){
            return "";
        }
        return entityMjRegionInfo.getRegionName();

    }
}
